var brandName_flag=true;
var seq_flag=true;

function brandName_validata(){
	
	var brandName=$("#brandName");
	
	if(!ge_two_letters_regex.test(brandName.val())){
        brandName_flag=false;
		$("#brandName_info").html("品牌名称必须大于2个非空白字符！");
		return;
	}

	var project_path=$("#form1").attr("project_path");
	
	$.ajax({
		   type: "get",
		   url: project_path+"/brand/isExistByBrandName",
		   data:{brandName:brandName.val()},
		   success: function(isExists){
		     if(isExists){
                 brandName_flag=false;
		 		$("#brandName_info").html("品牌名称已经存在！");
		     }else{
                 brandName_flag=true;
		 		$("#brandName_info").html("");
		     }
		   }
	});
}

function seq_validata(){

    var seq=$("#seq");

    if(!must_be_number_regex.test(seq.val())){
        seq_flag=false;
        $("#seq_info").html("显示顺序必须是数字！");
    }else{
        seq_flag=true;
        $("#seq_info").html("");
    }
}

$("#brandName").blur(function(){
    brandName_validata();
});

$("#seq").blur(function(){
    seq_validata();
});

$("#btn_submit").click(function(){

	var tag=$("#form1").attr("tag");

	if(tag=="append"){
        brandName_validata();
        if(brandName_flag)
            $("#form1").submit();
	}else{
        brandName_validata();
        seq_validata();
        if(brandName_flag&&seq_flag)
            $("#form1").submit();
	}
});